<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
  </head>
  <body>
    <div id="app">
      <my-list :list="list">
        <template #default="props">
          {{props.title}} <span v-if="props.title=='苹果'">👍</span>
        </template>
      </my-list>
      <my-list :list="list"></my-list>
    </div>
  </body>
  <script>
    let app = Vue.createApp({
      data() {
        return {
          list: ["苹果", "西瓜", "香蕉"],
        };
      },
    });
    app.component("my-list", {
      props: ["list"],
      data() {
        return {};
      },
      created() {
        // 获取组件调用时 传入的插槽内容
        console.log(this.$slots);
      },
      template: `
       <ul>
        <li v-for="item in list">
          <slot v-if="$slots.default" :title="item"></slot>
          <span v-else>{{item}}</span>  
        </li>
       </ul>
      `,
    });
    app = app.mount("#app");
  </script>
</html>
